<template>
  <a-drawer
    :title="formInfo.id==undefined?'新增':'修改'"
    :maskClosable="true"
    :width="drawerWidth"
    placement="right"
    :closable="true"
    @close="handleCancel"
    :destroyOnClose="true"
    :visible="visible"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">
    <a-spin :spinning="confirmLoading">
      <a-form-model
        ref="ruleForm"
        :model="formInfo"
        :label-col="$global.labelCol"
        :wrapper-col="$global.wrapperCol"
      >
            <a-row>
              <a-col :span="12">
            <a-form-model-item label="客户编号" prop="customerCode" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.customerCode" placeholder="请输入客户编号"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="客户姓名" prop="customerName" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.customerName" placeholder="请输入客户姓名"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="性别" prop="sex" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.sex" placeholder="请输入性别"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="婚姻状况" prop="maritalStatus" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.maritalStatus" placeholder="请输入婚姻状况"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="民族" prop="nation" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.nation" placeholder="请输入民族"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="出生日期" prop="birthday" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.birthday" placeholder="请输入出生日期"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="身份证号" prop="idCard" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.idCard" placeholder="请输入身份证号"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="照片路径" prop="photoPath" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.photoPath" placeholder="请输入照片路径"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="卡号" prop="cardNum" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.cardNum" placeholder="请输入卡号"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="联系电话" prop="tele" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.tele" placeholder="请输入联系电话"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="地址" prop="addr" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.addr" placeholder="请输入地址"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="职业" prop="occupation" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.occupation" placeholder="请输入职业"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="单位名称" prop="unitName" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.unitName" placeholder="请输入单位名称"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="部门名称" prop="deptName" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.deptName" placeholder="请输入部门名称"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="班组名称" prop="teamName" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.teamName" placeholder="请输入班组名称"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="来源=1 前台创建=2 团检导入=3自助终端机=4 外网预约" prop="source" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.source" placeholder="请输入来源=1 前台创建=2 团检导入=3自助终端机=4 外网预约"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="vip标识" prop="vipFlag">
              <a-select v-model="formInfo.vipFlag" placeholder="请选择vip标识">
                <a-select-option v-for="(item) in this.$sysDictOptions('vipFlag')" :key="item.k" :value="parseInt(item.k)">
                  {{ item.v }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="系统编码" prop="departCode" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.departCode" placeholder="请输入系统编码"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
            <a-col :span="24">
                <a-form-model-item  :labelCol="$global.labelTextAreaCol"  :wrapperCol="$global.wrapperTextAreaCol"  label="备注">
                    <a-input v-model="formInfo.remark" type="textarea"/>
                </a-form-model-item>
            </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
    <div class="drawer-bootom-button">
      <a-popconfirm title="确定放弃编辑？" @confirm="handleCancel" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="confirmLoading">提交</a-button>
    </div>
  </a-drawer>
</template>

<script>
  import { getAction, postAction } from '@/api/manage'
  export default {
    name: 'HealthCustomerEdit',
    components: {
    },
    data () {
      return {
        visible: false,
        confirmLoading: false,
        formInfo: {
          customerCode: undefined,
          customerName: undefined,
          sex: undefined,
          maritalStatus: undefined,
          nation: undefined,
          birthday: undefined,
          idCard: undefined,
          photoPath: undefined,
          cardNum: undefined,
          tele: undefined,
          addr: undefined,
          occupation: undefined,
          unitName: undefined,
          deptName: undefined,
          teamName: undefined,
          source: undefined,
          vipFlag: undefined,
          createTime: undefined,
          departCode: undefined,
          remark: undefined,
          wx: ''
        },
        drawerWidth: 800,
        url: {
          saveInfo: '/system/healthCustomer/save',
          getInfo: '/system/healthCustomer/info'
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit()
      },
      edit (record) {
        this.$objToOverride(this.formInfo, record)
        if (this.formInfo.id) {
          getAction(this.url.getInfo, { 'id': record.id }).then(res => {
            this.$nextTick(() => {
              this.formInfo = res.result.data
            })
          })
        }
        this.visible = true
      },
      // 确定
      handleSubmit () {
        // 触发表单验证
        this.confirmLoading = true
        this.$refs.ruleForm.validate(valid => {
          console.log(valid)
          if (valid) {
            postAction(this.url.saveInfo, this.formInfo).then(res => {
              this.$message.success(res.content)
              this.$emit('ok', this.formInfo)
              this.close()
            }).finally(() => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      // 关闭
      handleCancel () {
        this.close()
      },
      close () {
        this.$refs.ruleForm.resetFields()
        this.$objToReset(this.formInfo)
        this.$emit('close')
        this.visible = false
      },
      editorOk (val) {
        this.formInfo.content = val
      }
    }
  }
</script>
